<template>
	<view :class="PageCur=='taskmain'?'mainTop fullCla':'fullCla'">
		<view class="logoText">值班管理</view>
		<view v-if="errorList.length && PageCur=='taskmain'" class="errorTip" @click="toErrorList">
			您有{{errorList.length}}条问题待处理！
		</view>
		<view v-if="deptErrorList.length && PageCur=='taskmain'" class="deptErrorTip" @click="toDeptErrorList">
			您的部门有{{deptErrorList.length}}条问题待处理！
		</view>
		<!-- <home :cur="PageCur" v-if="PageCur=='home'" :key="commponent1Key"></home>
		<people v-if="PageCur=='people'" :key="commponent2Key"></people> -->
		<view class="showDom main" :cur="PageCur" v-if="PageCur=='taskmain'" :key="commponent1Key">
			<taskmain></taskmain>
		</view>
		
		<view class="showDom" v-if="PageCur=='notask'" :key="commponent2Key">
			<notask></notask>
		</view>
		<!-- 值班打卡 -->
		<view class="showDom" v-if="PageCur=='workcard'" :key="commponent3Key">
			<workcard></workcard>
		</view>
		<view class="showDom" v-if="PageCur=='errSub'" :key="commponent4Key">
			<errSub></errSub>
		</view>
		
		<people v-if="PageCur=='people'" :key="commponent5Key"></people>
		<view class="cu-bar tabbar bg-white shadow foot" style="display: flex;">
			<view class="navBottom" :class="PageCur=='taskmain'?'action':''" @click="NavChange" data-cur="taskmain">
				<view class="taskImg"></view>任务巡检
			</view>
			<view class="navBottom" :class="PageCur=='notask'?'action':''" @click="NavChange" data-cur="notask">
				<view class="notaskImg"></view>补充巡检
			</view>
			<view class="navBottom" :class="PageCur=='workcard'?'action':''" @click="NavChange" data-cur="workcard">
				<view class="workcardImg"></view>值班打卡
			</view>
			<view class="navBottom" :class="PageCur=='errSub'?'action':''" @click="NavChange" data-cur="errSub">
				<view class="errSubImg"></view>问题上报
			</view>
			<view class="navBottom" :class="PageCur=='people'?'action':''" @click="NavChange" data-cur="people">
				<view class="my"></view>我的
			</view>
		</view>
	</view>
</template>

<script>
	import { ACCESS_TOKEN,USER_NAME,USER_INFO } from "@/common/util/constants"
	import taskmain from '@/pages/taskmain/taskmain.vue';
	export default {
		components:{taskmain},
		data() {
		return {
				PageCur: 'home',
				commponent1Key: 0,
				commponent2Key: 0,
				commponent3Key: 0,
				commponent4Key: 0,
				commponent5Key: 0,
				errorList:[],
				deptErrorList:[]
			}
		},
		onLoad:function(){
			this.PageCur='taskmain'
			++this.commponent1Key
			++this.commponent2Key
			++this.commponent3Key;
			++this.commponent4Key
			++this.commponent5Key
			this.getErrorList();
			this.getDeptErrorList();
		},
		methods: {
			toErrorList(){
				uni.navigateTo({
					url: '/pages/errorSource/errorSource'
				})
			},
			toDeptErrorList(){
				uni.navigateTo({
					url: '/pages/deptErrorSource/deptErrorSource'
				})
			},
			NavChange: function(e) {
				let pageNav = e.currentTarget.dataset.cur;
				if(pageNav == 'taskmain'){
					this.getErrorList();
					this.getDeptErrorList();
				}
				//打卡不做过滤
				// if(pageNav == 'workcard'){
				// 	let userName = uni.getStorageSync(USER_INFO).username;
				// 	console.log()
				// 	let _this = this;
				// 	this.$http.get('/inspect/insClassesCheckInterval/queryIntervalByUserName?userName='+userName)
				// 		.then(res=>{
				// 			let flag = [];
				// 			res.data.map(item=>{
				// 				let numberOf = (new Date()).toLocaleTimeString('en-US', { hour12: false }).split(":").join("");
				// 				if(parseInt(numberOf)>= parseInt(item.class_time_pre.split(':').join(''))
				// 				  &&parseInt(numberOf)<= parseInt(item.class_time_end.split(':').join(''))
				// 				){
				// 					flag.push(item);
				// 				}
				// 			})
				// 			if(flag.length){
				// 				_this.PageCur = pageNav;
				// 			}else{
				// 				_this.$tip.toast('您当前不在可打卡时间段内！');
				// 			}
				// 		})
				// }else{
					this.PageCur = pageNav;
				// }
				
			},
			getDeptErrorList(){
				let _this = this;
				this.$http.get('/inspect/insClassesUnusualMsg/queryMsgByLoginUserQDeptAuthor')
					.then(res=>{
						console.log('查询异常res:',res.data.result)
						_this.deptErrorList = res.data.result.filter(item=>{
							return item.status == '1'
						})
					})
			},
			getErrorList(){
				let _this = this;
				this.$http.get('/inspect/insClassesUnusualMsg/queryIssueByUserId')
					.then(res=>{
						console.log('查询异常res:',res.data.result)
						_this.errorList = res.data.result.filter(item=>{
							return item.courseList[item.courseList.length-1].status=='1'
						})
					})
			}
		}
	}
</script>

<style scoped>
	.mainTop{
		width:100%;
		height: 100%;
		background: url("") no-repeat;
		background-size:contain;
		background-position: center top;
		/* padding-top: 300rpx; */
		border-top: 1px solid transparent;
		position: relative;
	}
	.logoText{
		display: none;
		font-size: 54rpx;
		transform:translateX(-50%);
		font-weight: bold;
		top:50rpx;
		left: 50%;
		color: #fff;
		position: absolute;
		letter-spacing: 2rpx;
	}
	.mainTop .logoText{
		display: block;
	}
	.errorTip{
		position: absolute;
		top: 250rpx;
		left: 50rpx;
		line-height: 50rpx;
		font-size: 24rpx;
		background-color: #fff;
		border-radius: 46rpx;
		background-color: rgba(255, 251, 213, 1);
		color: rgba(247, 164, 1, 1);
		border-left: none;
		padding: 0 24rpx;
	}
	.deptErrorTip{
		position: absolute;
		top: 250rpx;
		right: 50rpx;
		line-height: 50rpx;
		font-size: 24rpx;
		background-color: #fff;
		border-radius: 46rpx;
		background-color: rgba(255, 251, 213, 1);
		color: rgba(247, 164, 1, 1);
		border-left: none;
		padding: 0 24rpx;
	}
	page,.showDom,.fullCla{
		width: 100%;
		height: 100%;
	}
	.showDom.main{
		margin-top: 300rpx;
		height: calc(100% - 300rpx);
	}
	.action{
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		font-weight: bold;
	}
	.notaskImg{
		width: 18px;
		height: 18px;
		background: url(../../static/notask.png) no-repeat;
		background-size: 100% 100%;
	}
	.action .notaskImg{
		background: url(../../static/notask_act.png) no-repeat;
		background-size: 100% 100%;
	}
	.taskImg{
		width: 18px;
		height: 18px;
		background: url(../../static/task.png) no-repeat;
		background-size: 100% 100%;
	}
	.action .taskImg{
		background: url(../../static/task_act.png) no-repeat;
		background-size: 100% 100%;
	}
	.my{
		width: 18px;
		height: 18px;
		background: url(../../static/my.png) no-repeat;
		background-size: 100% 100%;
	}
	.action .my{
		background: url(../../static/my_act.png) no-repeat;
		background-size: 100% 100%;
	}
	.errSubImg{
		width: 18px;
		height: 18px;
		background: url(../../static/errSub.png) no-repeat;
		background-size: 100% 100%;
	}
	.action .errSubImg{
		background: url(../../static/errSub_act.png) no-repeat;
		background-size: 100% 100%;
	}
	.workcardImg{
		width: 18px;
		height: 18px;
		background: url(../../static/workcard.png) no-repeat;
		background-size: 100% 100%;
	}
	.action .workcardImg{
		background: url(../../static/workcard_act.png) no-repeat;
		background-size: 100% 100%;
	}
	.navBottom{
		display: flex!important;
		align-items: center;
		gap:2px;
		flex-direction: column;
		width: 20%;
	}
</style>
